package com.l.web.service.webcontent;

import org.l.qiao.Cluster;
import org.l.qiao.Page;
import org.l.qiao.search.Field;
import org.l.qiao.search.Sort;
import com.l.web.service.ServiceSupport;
import org.apache.log4j.Logger;

public class WebContentListService extends ServiceSupport {

    public static final Logger LOGGER = Logger.getLogger(WebContentListService.class);

    private WebContentDAO webContentDAO;

    public WebContentListService() {
    }

    public void setWebContentDAO(WebContentDAO webContentDAO) {
        this.webContentDAO = webContentDAO;
    }

    public String execute() {
        String type = form.getString(TYPE);

        if ("list".equals(type)) {
            return list();
        } else {
            String webNodeId = form.getString("webNodeId");
            context.put("webNodeId", webNodeId);
            return "listForm";
        }
    }

    private String list() {

        Page page = this.getPage();
        WebContent webContent = new WebContent();
        boolean result = form.getCluster(webContent);
        webContent.initWebNodeId();
        LOGGER.debug("查询信息：" + webContent);

        Field field = new Field(WebContent.TITLE, WebContent.WEB_NODE_ID, WebContent.CREATED);
        Sort sort = new Sort();
        sort.desc(WebContent.CREATED);

        Cluster webContents = webContentDAO.findPage(webContent, field, null, page);
        context.put("webContents", webContents);

        return LIST;
    }
}
